class Comment < ActiveRecord::Base

  acts_as_blog
  
  cattr_reader :per_page
  @@per_page = 30
  
  belongs_to :post
  belongs_to :user
  
  attr_accessible :body, :name, :email, :post_id
  
  validates_presence_of :body, :name, :email
  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-zA-Z]{2,})$/, :message => "must be an email address"
  validates_format_of :name, :body, :with => /^[^\<\>]*$/
  
  def before_save
    self.parsed_body = Comment.convert_to_html(self.body,'markdown',[:filter_html])
    self.published = true unless self.published
  end
  
  def after_save
    EmailNotification.deliver_comment(self) if APP_SETTINGS[:comment_notify_email]
  end
  
  def after_destroy
  end
  
end
